﻿define([
    'dojo/_base/declare',
    'esri/geometry/Point',
    'geomap/plugins/layers/DyTrajectoryLayer',
], function (declare, Point, BaseDivsLayer, Div) {
    var DyTrajectoryLayer = declare([BaseDivsLayer], {
        setData: function (mapView, layer) {
            var me = this;
            var options = layer.layer || {};
            var data = $.extend(true, [], options.data);
            var mapUtils = mapView.mapUtils;
            data.map(function (item, i) {
                var lngLatArray = mapUtils.toLngLatArray(mapView, item.children, options);
                var points = [];
                lngLatArray.map(function (lngLat, index) {
                    var point = mapUtils.createPoint(mapView, lngLat);
                    points.push(point);
                    if (index == lngLatArray.length - 1) {
                        var trajectoryLine = item.options || options.options || {};
                        trajectoryLine.points = points;
                        me.add(trajectoryLine);
                        if (i == data.length - 1) {
                            if (typeof options.callback == 'function') {
                                options.callback(layer);
                            }
                        }
                    }
                });
            });
        },
        getGraphicLocation: function (mapView, esriEvent) {
            var geometry = esriEvent.graphic.geometry;
            var lngFieldName = mapView.getLngFieldName();
            var latFieldName = mapView.getLatFieldName();
            var location = {};
            location[lngFieldName] = geometry.x;
            location[latFieldName] = geometry.y;
            return location;
        },
    });
    return DyTrajectoryLayer;
});
